/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import beans.util.TravelId;
import controllers.EscursioneFacade;
import entities.Camera;
import entities.Escursione;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

/**
 *
 * @author riccardo
 */
@ManagedBean
@RequestScoped
public class FilEscursioneController extends AbstractController<Escursione> implements Serializable {

    @Inject
    private EscursioneFacade ejbFacade;
    
    @ManagedProperty(value="#{travelId}")
    private TravelId tid; 

    public TravelId getTid() {
        return tid;
    }

    public void setTid(TravelId tid) {
        this.tid = tid;
    }
    public FilEscursioneController() {
        super(Escursione.class);
    }

    @PostConstruct
    public void init() {
        super.setFacade(ejbFacade);
        
    }

    @Override
    public List<Escursione> getItems() {
        if (items == null) {
        String id = tid.getID();
            System.out.println("ciao sono il viaggio" + id);

            if ("0".equals(id) || id == null) {
                items = this.ejbFacade.findAll();
            } else {
                items = this.ejbFacade.findByIdViaggio(Integer.parseInt(id));
            }
        }
        return items;
    }
}
